// 只要文件夹里有index.tsx，就是需要作为路由的
let files = require.context('./pages',true,/\index.tsx$/);
let pathArr: string[] = []
let routeArr: {exact:boolean; path: string; title: string; routes:any[]}[] = []
files.keys().forEach((fileName: string) => {
  let path = fileName.split('/index.tsx')[0].split('.')[1] // ./home/index.tsx => ./home => /home
  if(path!=='/error-page'){
    pathArr.push(path)
  }
})

pathArr.sort((a,b)=>a.length-b.length)

pathArr.forEach(item=>{
  if(item.split('/').length<3){
    routeArr.push({exact: true, path:item, title:item.split('/')[1], routes:[]})
  }else{
    let pathArr = item.split('/')
    routeArr.forEach(route=>{
      if(route.title === pathArr[1]) {
        route.routes.push({exact:true,path:item,title:pathArr[2]})
      }
    })
  }
})

export default routeArr
